package controllers;

import play.data.Form;
import play.mvc.*;

import views.html.*;

import static play.data.Form.form;

public class Application extends Controller {
    public static class Hello {
         public String name;
        public Integer repeat=1;
        public String color;
    }

    public static Result index() {

        return ok(index.render("功能菜单"));
    }

    public static Result showForm() {

        return ok(getForm.render(form(Hello.class)));
    }
    /**
     * Handles the form submission.
     */
    public static Result sayHelloGet(){
        Form<Hello> form = form(Hello.class).bindFromRequest();
        if(form.hasErrors()) {
            return badRequest(getForm.render(form));
        } else {
            Hello data = form.get();
            return ok(
                    hello.render(data.name, data.repeat, data.color)
            );
        }
    }
    public static Result sayHelloPost(){
        Form<Hello> form = form(Hello.class).bindFromRequest();
        if(form.hasErrors()) {
            return badRequest(getForm.render(form));
        } else {
            Hello data = form.get();
            return ok(
                    hello.render(data.name, data.repeat, data.color)
            );
        }
    }
}
